@extends('Admin.Layout.main')
@section('privateheader')
    <link rel="stylesheet" href="{{__BASE__}}/admin/plugins/multiSelect/multi-select-metro.css">
@endsection
@section('content')
    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-6">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{$data['pageOrButton']}} </h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    @if($data['flag'] == 1)
                        <form role="form" action="/admini/member" method="post" id="menumgmt-form" enctype="multipart/form-data">
                            @elseif($data['flag'] == 2)
                                <form role="form" action="/admini/member/{{$data['id'] or ''}}" method="post" id="menumgmt-form" enctype="multipart/form-data">
                                    {{ method_field('PUT') }}
                                    @endif
                                    <input type="hidden" name="_token" value="{{csrf_token()}}">
                                    <div class="box-body">
                                        <div class="form-group datadd-form-show-error has-error" <?php echo !empty($errors->all()) ? 'style="display:block;"' : '';?>><?php echo !empty($errors->all()) ? implode(' ',$errors->all()) : '';?></div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">设置代理类型</label>
                                            <select name="user_role" class="form-control">
                                                <option value="1" <?php echo !empty($data['editList']->user_role) && $data['editList']->user_role == 1? 'selected="selected"': '';?>>普通用户</option>
                                                <option value="2" <?php echo !empty($data['editList']->user_role) && $data['editList']->user_role == 2? 'selected="selected"': '';?>>准代理</option>
                                                <option value="3" <?php echo !empty($data['editList']->user_role) && $data['editList']->user_role == 3? 'selected="selected"': '';?>>个代理</option>
                                                <option value="4" <?php echo !empty($data['editList']->user_role) && $data['editList']->user_role == 4? 'selected="selected"': '';?>>省代理</option>
                                                <option value="5" <?php echo !empty($data['editList']->user_role) && $data['editList']->user_role == 5? 'selected="selected"': '';?>>市代理</option>
                                                <option value="6" <?php echo !empty($data['editList']->user_role) && $data['editList']->user_role == 6? 'selected="selected"': '';?>>区代理</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">省份</label>
                                            <select name="province_id" class="form-control">
                                                <option value="">-- 请选择 --</option>
                                                @if(!empty($data['privoide']))
                                                    @foreach($data['privoide'] as $v)
                                                        <option <?php echo !empty($data['editList']->province_id) && $data['editList']->province_id == $v->id ? 'selected="selected"' : '';?> value="{{$v->id or ''}}">{{$v->name or ''}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>

                                        <div class="form-group">
                                            <label for="exampleInputEmail1">市</label><br/>
                                            <select name="city_id" class="form-control">
                                                <option value="">-- 请选择 --</option>
                                                @if(!empty($data['city']))
                                                    @foreach($data['city'] as $v1)
                                                        <option <?php echo !empty($data['editList']->city_id) && $data['editList']->city_id == $v1->id ? 'selected="selected"' : '';?> value="{{$v1->id or ''}}">{{$v1->name or ''}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">区</label><br/>
                                            <select name="area_id" class="form-control">
                                                <option value="">-- 请选择 --</option>
                                                @if(!empty($data['area']))
                                                    @foreach($data['area'] as $v2)
                                                        <option <?php echo !empty($data['editList']->area_id) && $data['editList']->area_id == $v2->id ? 'selected="selected"' : '';?> value="{{$v2->id or ''}}">{{$v2->name or ''}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">代理点数</label>
                                            <input type="text" placeholder="输入代理点数" name="point" value="{{$data['editList']->point or 0}}" class="form-control">
                                        </div>
                                    </div>
                                    <!-- /.box-body -->

                                    <div class="box-footer">
                                        <button class="btn btn-primary" type="submit">{{$data['pageOrButton']}}</button>
                                        <a href="/admini/member" class="btn bg-olive">返回列表</a>
                                    </div>
                                </form>
                </div>
                <!-- /.box -->
            </div>
            <!--/.col (left) -->
        </div>
        <!-- /.row -->
    </section>
@endsection
@section('privatefooter')
    <!-- jquery-validator -->
    <script src="{{__BASE__}}/admin/plugins/jquery-validate/jquery.validate.min.js"></script>
    <script src="{{__BASE__}}/admin/plugins/jquery-validate/localization/messages_zh.min.js"></script>
    <script type="text/javascript" src="{{__BASE__}}/admin/plugins/multiSelect/jquery.multi-select.js"></script>
    <script type="text/javascript" src="{{__BASE__}}/admin/dist/js/form-validate/menumgmt.js"></script>
    <script>
        //获取市信息
        $("select[name=province_id]").on("change",function(){
            var privince = $(this).val();
            //根据选择的省获取市
            if(privince == "")
            {
                $("select[name=city_id]").html('<option value="">-- 请选择 --</option>');
                $("select[name=area_id]").html('<option value="">-- 请选择 --</option>');
            }else{
                $.ajax({
                    url:"/admini/getcity",
                    type:'post',
                    data:{"_token":"{{ csrf_token()}}","id":privince},
                    success:function(msg)
                    {
                        var obj = eval("("+msg+")");
                        if(obj['code'] == -1)
                        {
                            alert(obj['msg']);
                        }else{
                            $("select[name=city_id]").html(obj['msg']);
                        }
                    },
                    error:function(){
                        alert("网络繁忙,请稍后重试!");
                    }
                });
            }
        });

        //获取区信息
        $("select[name=city_id]").on("change",function(){
            var city = $(this).val();
            //根据选择的省获取市
            if(city == "")
            {
                $("select[name=area_id]").html('<option value="">-- 请选择 --</option>');
            }else{
                $.ajax({
                    url:"/admini/getcity",
                    type:'post',
                    data:{"_token":"{{ csrf_token()}}","id":city},
                    success:function(msg)
                    {
                        var obj = eval("("+msg+")");
                        if(obj['code'] == -1)
                        {
                            alert(obj['msg']);
                        }else{
                            $("select[name=area_id]").html(obj['msg']);
                        }
                    },
                    error:function(){
                        alert("网络繁忙,请稍后重试!");
                    }
                });
            }
        });
    </script>
@endsection